/*************************************************************
 * 主要介绍构造函数的种类以及用法
 * 1、什么是构造函数
 *    类的构造函数是一种特殊的成员函数，在每次创建新类的时候执行，没有返回值，
 *    函数名与类名相同，可以改变参数类型/个数/顺序实现重载。
 *    构造函数分为：有参构造/无参构造两种类型。
 * 2、为什么会有构造函数
 *    主要用于完成类对象成员变量的初始化。
 * 3、如何使用构造函数
 *    定义类对象时调用构造
 * **********************************************************/
#include "common.h"
using namespace std;

Construct::Construct(int age_, int high_, char* addr_)
{
    age = age_;
    high = high_;
    addr = new char[16];
    strcpy(addr, addr_);
}

Construct::Construct(int age_, int high_, char* addr_, std::string name_)
{
    age = age_;
    high = high_;
    addr = new char[16];
    strcpy(addr, addr_);
    name = name_;
}

Construct::Construct(const Construct& con)
{
    age = con.age;
    high = con.high;
    addr = new char[16];
    strcpy(addr, con.addr);
    name = con.name;
}

void Construct::show()
{
    cout << "Construct age = " << age << endl;
    cout << "Construct high = " << high << endl;
    cout << "Construct addr = " << addr << endl;
    cout << "Construct name = " << name << endl;
}

Construct::~Construct()
{
    delete addr;
    addr = nullptr;
}

int main()
{
    string name = "wang";
    Construct* con1 = new Construct(12, 183, "chengdu", name);
    con1->show();

    Construct con2(8, 175, "wang");
    con2.show();

    Construct con3(con2);
    con3.show();

    return 0;
}